﻿using System;
using Cotrobaie.UsersWebService;

namespace Cotrobaie
{
    public partial class RecuperareParola : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Partea1.Visible = Session["UserID"] == null && Request.QueryString["ActivationCode"] == null && Request.QueryString["user"] == null && Request.QueryString["email"] == null;
            Partea2.Visible = !Partea1.Visible;
            if (Partea2.Visible) { try { UsernameRecParola.Text = Request.QueryString["user"]; EmailRecParola.Text = Request.QueryString["email"]; } catch { } }
            if (Session["UserID"] != null) Response.Redirect("Home.aspx");
        }

        protected void contactb_Click(object sender, EventArgs e)
        {
            if (Session["CaptchaImageText"].ToString().ToLower() != TextBoxCapcha.Text.ToLower())
            { salvareokPoza.Src = "images/nooksmall.png"; salvareokPoza.Alt = "salvare not ok"; salvareokMesaj.InnerHtml = "Codul Captcha este gresit"; salvareok.Visible = UpdateTimer.Enabled = true; return; }

            if (Partea1.Visible)
                using (UsersSoapClient serviciu = new UsersSoapClient("UsersSoap"))
                {
                    var result = serviciu.RecuperareParola(username.Text, email.Text);
                    salvareokMesaj.InnerHtml = result.Mesaj;
                    if (!result.Success) { salvareokPoza.Src = "images/nooksmall.png"; salvareokPoza.Alt = "salvare not ok"; }
                    else { salvareokPoza.Src = "images/oksmall.png"; salvareokPoza.Alt = "salvare ok"; }
                    salvareok.Visible = UpdateTimer.Enabled = true;
                }
        }
        protected void modif_Click(object sender, EventArgs e)
        {
            if(Partea2.Visible)
                using (UsersSoapClient serviciu = new UsersSoapClient("UsersSoap"))
                {
                    var result = serviciu.RecuperareParolaIntrodNouaParola(UsernameRecParola.Text, EmailRecParola.Text, Request.QueryString["ActivationCode"].ToString(), Parola1.Text);
                    salvareokMesaj.InnerHtml = result.Mesaj;
                    if (!result.Success) { salvareokPoza.Src = "images/nooksmall.png"; salvareokPoza.Alt = "salvare not ok"; }
                    else { salvareokPoza.Src = "images/oksmall.png"; salvareokPoza.Alt = "salvare ok"; }
                    salvareok.Visible = UpdateTimer.Enabled = true;
                }
        }
        protected void UpdateTimer_Tick(object sender, EventArgs e)
        {
            salvareok.Visible = UpdateTimer.Enabled = false;

        }

        protected void goHome(object sender, EventArgs e)
        {
            Response.Redirect("~/Home.aspx");
        }
    }
}